﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using GPSTrackingWebsiteManager.ClassManager;

namespace GPSTrackingWebsiteManager.Manager.Pages
{
    public partial class LinealViewClientsRoute : ClassManager.SessionManagerPage
    {

        public class EnumValue : System.Attribute
        {
            private string _value;
            public EnumValue(string value)
            {
                 _value = value;
            }
            public string Value
            {
                get { return _value; }
            }
        }

        public static class EnumString
        {
            public static string GetStringValue(Enum value)
            {
            string output = null;
            Type type = value.GetType();
            FieldInfo fi = type.GetField(value.ToString());
            EnumValue[] attrs = fi.GetCustomAttributes(typeof(EnumValue),false) as EnumValue[];
            if (attrs.Length > 0)
            {
                output = attrs[0].Value;
            }
                return output;
            }
        }

        public enum HomeType
        {
           [EnumValue("Home-Red.png")] Red,
           [EnumValue("Home-Green.png")] Green,
           [EnumValue("Home-Lile.png")] Lile,
           [EnumValue("Home-Fail.png")] Fail, 
           [EnumValue("Home-Square.png")] Square,
           [EnumValue("")] None

        }

        public struct ColumnInfo
        {
            public string ClientName;
            public HomeType HomeImage;
            public System.Drawing.Color LineColor;
            public string TimeText;
        };

        public struct ColumnInfoTotal
        {
            public string LineTop;
            public System.Drawing.Color ColorSeparate;
            public string LineBottom;
        };

        
                
        protected void Page_Load(object sender, EventArgs e)
        {

            getInfo();
            //getStaticsTables();
        }

        protected SessionManager getSessionManager()
        {
            return (SessionManager)HttpContext.Current.Session["SessionManager"];
        }

        public void getInfo()
        {
            List<ColumnInfo> columnInfoList;
            ColumnInfoTotal columnInfoTotal;
            DataSet dsEstimated = GPSTrackingDBV2Custom.Data.DataRepository.ClientsToVisitProvider.GetAgentsEstimatedTimeReportsByUser(getSessionManager().CompanyIDSelectedComboBox, getSessionManager().LinealViewInfo_Username, getSessionManager().LinealViewInfo_GPSImei, getSessionManager().LinealViewInfo_Date);

            if (dsEstimated.Tables.Count >= 0)
            {
                //setGeneralTable(ds.Tables[0], ds.Tables[1], true, null, 0, ds.Tables[0].Rows.Count, 0);

                columnInfoList = getColumnInfoListClients(dsEstimated.Tables[0]);
                columnInfoTotal = getColumnInfoTotalClients(dsEstimated.Tables[1], 0, dsEstimated.Tables[0].Rows.Count, 0);

                lblTitleTable1.Text = "Óptimo";
                BuildTable(Table1, columnInfoList, columnInfoTotal);


                //setGeneralTable(ds.Tables[2], ds.Tables[3], false, ds.Tables[4], decimal.Parse(ds.Tables[3].Rows[0]["TotalDistanceKmTravel"].ToString()) - decimal.Parse(ds.Tables[1].Rows[0]["TotalDistanceKmTravel"].ToString()), ds.Tables[0].Rows.Count, ds.Tables[4].Rows.Count);
            }

            DataSet dsReal = GPSTrackingDBV2Custom.Data.DataRepository.ClientsToVisitProvider.GetAgentsRealTimeReportsByUser(getSessionManager().CompanyIDSelectedComboBox, getSessionManager().LinealViewInfo_Username, getSessionManager().LinealViewInfo_GPSImei, getSessionManager().LinealViewInfo_Date);

            if (dsReal.Tables.Count >= 0)
            {
                
                columnInfoList = getColumnInfoListClientsNoVisit(dsReal.Tables[2], getColumnInfoListClients(dsReal.Tables[0])); 

                columnInfoTotal = getColumnInfoTotalClients(dsReal.Tables[1], decimal.Parse(dsReal.Tables[1].Rows[0]["TotalDistanceKmTravel"].ToString()) - decimal.Parse(dsEstimated.Tables[1].Rows[0]["TotalDistanceKmTravel"].ToString()), dsReal.Tables[0].Rows.Count - 1, dsReal.Tables[2].Rows.Count);

                lblTitleTable2.Text = "Último Realizado: " + getSessionManager().LinealViewInfo_Date.ToShortDateString();
                BuildTable(Table2, columnInfoList, columnInfoTotal);

                //setGeneralTable(ds.Tables[2], ds.Tables[3], false, ds.Tables[4], decimal.Parse(ds.Tables[3].Rows[0]["TotalDistanceKmTravel"].ToString()) - decimal.Parse(ds.Tables[1].Rows[0]["TotalDistanceKmTravel"].ToString()), ds.Tables[0].Rows.Count, ds.Tables[4].Rows.Count);
            }

            DataSet dsAverage = GPSTrackingDBV2Custom.Data.DataRepository.ClientsToVisitProvider.GetAgentsAverageTimeReportsByUser(getSessionManager().CompanyIDSelectedComboBox, getSessionManager().LinealViewInfo_Username, getSessionManager().LinealViewInfo_GPSImei, getSessionManager().LinealViewInfo_DateBegin, getSessionManager().LinealViewInfo_DateEnd);

            if (dsAverage.Tables.Count >= 0)
            {

                //columnInfoList = ;//, getColumnInfoListClients(dsReal.Tables[0]));
                columnInfoList = getColumnInfoListClientsNoVisit(dsAverage.Tables[3], getColumnInfoListClientsAverage(dsAverage.Tables[0])); 

                columnInfoTotal = getColumnInfoTotalClientsAverage(dsAverage.Tables[1], int.Parse(dsAverage.Tables[2].Rows[0]["CantClientsNoVisited"].ToString()));

                lblTitleTable3.Text = "Promedio: " + getSessionManager().LinealViewInfo_DateBegin.ToShortDateString() + " - " + getSessionManager().LinealViewInfo_DateEnd.ToShortDateString();
                BuildTable(Table3, columnInfoList, columnInfoTotal);

                //setGeneralTable(ds.Tables[2], ds.Tables[3], false, ds.Tables[4], decimal.Parse(ds.Tables[3].Rows[0]["TotalDistanceKmTravel"].ToString()) - decimal.Parse(ds.Tables[1].Rows[0]["TotalDistanceKmTravel"].ToString()), ds.Tables[0].Rows.Count, ds.Tables[4].Rows.Count);
            }


        }

        public List<ColumnInfo> getColumnInfoListClients(DataTable GeneralTable)
        {
            List<ColumnInfo> listColumnInfo = new List<ColumnInfo>();
            ColumnInfo info = new ColumnInfo();
            string timeTravel = "";
            string timeVisit = "";

            foreach (DataRow row in GeneralTable.Rows)
            {

                timeTravel = "";
                timeVisit = "";

                if (row["LastClientID"].ToString() == "-1")
                {
                    info = new ColumnInfo();
                    info.ClientName = row["LastClientName"].ToString();
                    info.HomeImage = HomeType.Red;
                    info.LineColor = System.Drawing.Color.Red;
                    info.TimeText += "Hora&nbspSalida*";
                    info.TimeText += row["LeftDateTime"].ToString();
                    listColumnInfo.Add(info);
                }

                info = new ColumnInfo();
                info.LineColor = System.Drawing.Color.Red;
                info.HomeImage = HomeType.None;

                if (int.Parse(row["HoursTravel"].ToString()) > 0)
                {
                    timeTravel = row["HoursTravel"].ToString() + "&nbsph&nbsp";
                }

                timeTravel += row["MinutesTravel"].ToString() + "&nbspmin";

                info.TimeText += "Tiempo&nbspRuta*";
                info.TimeText += timeTravel + "*";
                info.TimeText += row["DistanceKmTravel"].ToString() + "&nbspKm";
                listColumnInfo.Add(info);

                info = new ColumnInfo();
                info.ClientName = row["ClientName"].ToString();

                if (row["ClientID"].ToString() == "-1")
                    info.HomeImage = HomeType.Red;
                else
                    info.HomeImage = HomeType.Green;

                info.LineColor = System.Drawing.Color.Red;

                info.TimeText += "Hora&nbspLlegada*";
                info.TimeText += row["ArriveDateTime"].ToString() + "*";

                if (int.Parse(row["Hours"].ToString()) > 0)
                {
                    timeVisit = row["Hours"].ToString() + "&nbsph&nbsp";
                }

                timeVisit += row["Minutes"].ToString() + "&nbspmin";

                info.TimeText += "*Estadía*" + timeVisit;
                listColumnInfo.Add(info);

            }
            return listColumnInfo;
        }

        public List<ColumnInfo> getColumnInfoListClientsNoVisit(DataTable ClientsNoVisited, List<ColumnInfo> listColumnInfo)
        {
            List<ColumnInfo> mylistColumnInfo = listColumnInfo;
            ColumnInfo info = new ColumnInfo();
            
            foreach (DataRow row in ClientsNoVisited.Rows)
            {
                info = new ColumnInfo();
                info.ClientName = row["CurrentClientName"].ToString();
                info.HomeImage = HomeType.Fail;
                info.LineColor = System.Drawing.Color.Red;
                mylistColumnInfo.Add(info);
            }
            return mylistColumnInfo;
        }

        public List<ColumnInfo> getColumnInfoListClientsAverage(DataTable GeneralTable)
        {
            List<ColumnInfo> listColumnInfo = new List<ColumnInfo>();
            ColumnInfo info = new ColumnInfo();
            string timeTravel = "";
            string timeVisit = "";

            foreach (DataRow row in GeneralTable.Rows)
            {

                timeTravel = "";
                timeVisit = "";

                info = new ColumnInfo();
                info.ClientName = row["ClientName"].ToString();

                info.LineColor = System.Drawing.Color.Red;

                if (int.Parse(row["HoursAverageOnClients"].ToString()) > 0)
                {
                    timeVisit = row["HoursAverageOnClients"].ToString() + "&nbsph&nbsp";
                }

                timeVisit += row["MinutesAverageOnClients"].ToString() + "&nbspmin";

                info.TimeText += "*Estadía&nbspPromedio*" + timeVisit;
                listColumnInfo.Add(info);

            }
            return listColumnInfo;
        }

        public ColumnInfoTotal getColumnInfoTotalClients(DataTable ResumenTable, decimal KmsDiference, int totalClientsToVisit, int totalClientsNoVisit)
        {
            
            ColumnInfoTotal columnInfoTotal = new ColumnInfoTotal();
            string timeTravel = "";
            string timeGlobal = "";
            string timeVisit = "";

            foreach (DataRow row in ResumenTable.Rows)
            {
                timeTravel = "";
                timeGlobal = "";
                timeVisit = "";

                //Total Section
                columnInfoTotal = new ColumnInfoTotal();
                columnInfoTotal.LineTop = "<strong>Costos&nbspAdicionales:</strong>*Kilometros&nbspExtras:&nbsp" + KmsDiference.ToString() + "&nbspKm*Clientes&nbspVisitados:&nbsp" + totalClientsToVisit.ToString() + "*Clientes&nbspsin&nbspvisitar:&nbsp" + totalClientsNoVisit.ToString();
                columnInfoTotal.LineBottom = "<strong>Totales&nbspde&nbspla&nbspruta:</strong>*";

                if (int.Parse(row["TotalHours"].ToString()) > 0)
                {
                    timeVisit = row["TotalHours"].ToString() + "&nbsph&nbsp";
                }

                timeVisit += row["TotalMinutes"].ToString() + "&nbspmin";

                columnInfoTotal.LineBottom += "Estadía:&nbsp" + timeVisit + "*";

                if (int.Parse(row["TotalHoursTravel"].ToString()) > 0)
                {
                    timeTravel = row["TotalHoursTravel"].ToString() + "&nbsph&nbsp";
                }

                timeTravel += row["TotalMinutesTravel"].ToString() + "&nbspmin";

                columnInfoTotal.LineBottom += "Tiempo&nbspRuta:&nbsp" + timeTravel + "*";

                columnInfoTotal.LineBottom += "Kilometros&nbspRecorridos:&nbsp" + row["TotalDistanceKmTravel"].ToString() + "&nbspKm*";

                if (int.Parse(row["TotalGlobalHours"].ToString()) > 0)
                {
                    timeGlobal = row["TotalGlobalHours"].ToString() + "&nbsph&nbsp";
                }

                timeGlobal += row["TotalGlobalMinutes"].ToString() + "&nbspmin";

                columnInfoTotal.LineBottom += "<strong>Tiempo&nbspTotal:&nbsp" + timeGlobal + "</strong>";
                columnInfoTotal.ColorSeparate = System.Drawing.Color.Red;
            }

            return columnInfoTotal;
        }

        public ColumnInfoTotal getColumnInfoTotalClientsAverage(DataTable ResumenTable, int totalClientsNoVisit)
        {

            ColumnInfoTotal columnInfoTotal = new ColumnInfoTotal();
            string timeTravel = "";
            string timeGlobal = "";
            string timeVisit = "";

            int porcVisited;

            foreach (DataRow row in ResumenTable.Rows)
            {
                timeTravel = "";
                timeGlobal = "";
                timeVisit = "";

                porcVisited = (int)(decimal.Parse(row["CantClients"].ToString()) / ((decimal.Parse(row["CantClients"].ToString()) + totalClientsNoVisit) == 0 ? 1 : (decimal.Parse(row["CantClients"].ToString()) + totalClientsNoVisit)) * 100);

                //Total Section
                columnInfoTotal = new ColumnInfoTotal();
                columnInfoTotal.LineTop = "<strong>Costos&nbspAdicionales:</strong>*%&nbspClientes&nbspVisitados:&nbsp";
                columnInfoTotal.LineTop += porcVisited.ToString();
                columnInfoTotal.LineTop += "*%&nbspClientes&nbspsin&nbspvisitar:&nbsp" + (100 - porcVisited).ToString();
                columnInfoTotal.LineBottom = "<strong>Totales&nbspde&nbspla&nbspruta:</strong>*";

                if (int.Parse(row["HoursAverageOnClients"].ToString()) > 0)
                {
                    timeVisit = row["HoursAverageOnClients"].ToString() + "&nbsph&nbsp";
                }

                timeVisit += row["MinutesAverageOnClients"].ToString() + "&nbspmin";

                columnInfoTotal.LineBottom += "Estadía&nbspPromedio:&nbsp" + timeVisit + "*";

                columnInfoTotal.LineBottom += "Total&nbspKilometros&nbspRecorridos:&nbsp" + row["TotalDistanceTravel"].ToString() + "&nbspKm*";

            }

            return columnInfoTotal;
        }

        public void setGeneralTable(DataTable GeneralTable, DataTable ResumenTable, bool isEstimatedGrid, DataTable ClientsNoVisited, decimal KmsDiference, int totalClientsToVisit, int totalClientsNoVisit)
        {

            List<ColumnInfo> listColumnInfo = new List<ColumnInfo>();
            ColumnInfo info = new ColumnInfo();
            ColumnInfoTotal columnInfoTotal = new ColumnInfoTotal();
            string timeTravel = "";
            string timeGlobal = "";
            string timeVisit = "";

            foreach (DataRow row in GeneralTable.Rows)
            {

                timeTravel = "";
                timeGlobal = "";
                timeVisit = "";

                if (row["LastClientID"].ToString() == "-1")
                {
                    info = new ColumnInfo();
                    info.ClientName = row["LastClientName"].ToString();
                    info.HomeImage = HomeType.Red;
                    info.LineColor = System.Drawing.Color.Red;
                    info.TimeText += "Hora&nbspSalida*";
                    info.TimeText += row["LeftDateTime"].ToString();
                    listColumnInfo.Add(info);
                }

                info = new ColumnInfo();
                info.LineColor = System.Drawing.Color.Red;
                info.HomeImage = HomeType.None;

                if (int.Parse(row["HoursTravel"].ToString()) > 0)
                {
                    timeTravel = row["HoursTravel"].ToString() + "&nbsph&nbsp";
                }

                timeTravel += row["MinutesTravel"].ToString() + "&nbspmin";

                info.TimeText += "Tiempo&nbspRuta*";
                info.TimeText += timeTravel + "*";
                info.TimeText += row["DistanceKmTravel"].ToString() + "&nbspKm";
                listColumnInfo.Add(info);

                info = new ColumnInfo();
                info.ClientName = row["ClientName"].ToString();
                
                if (row["ClientID"].ToString() == "-1")
                    info.HomeImage = HomeType.Red;
                else
                    info.HomeImage = HomeType.Green;

                info.LineColor = System.Drawing.Color.Red;

                info.TimeText += "Hora&nbspLlegada*";
                info.TimeText += row["ArriveDateTime"].ToString() + "*";

                if (int.Parse(row["Hours"].ToString()) > 0)
                {
                    timeVisit = row["Hours"].ToString() + "&nbsph&nbsp";
                }

                timeVisit += row["Minutes"].ToString() + "&nbspmin";

                info.TimeText += "*Estadía*" + timeVisit;
                listColumnInfo.Add(info);

            }

            if (!isEstimatedGrid) {
                foreach(DataRow row in ClientsNoVisited.Rows){
                    info = new ColumnInfo();
                    info.ClientName = row["CurrentClientName"].ToString();
                    info.HomeImage = HomeType.Fail;
                    info.LineColor = System.Drawing.Color.Red;
                    listColumnInfo.Add(info);
                }
            }

            foreach (DataRow row in ResumenTable.Rows)
            {
                timeTravel = "";
                timeGlobal = "";
                timeVisit = "";

                //Total Section
                columnInfoTotal = new ColumnInfoTotal();
                columnInfoTotal.LineTop = "<strong>Costos&nbspAdicionales:</strong>*Kilometros&nbspExtras:&nbsp" + KmsDiference.ToString() + "&nbspKm*Clientes&nbspVisitados:&nbsp" + (totalClientsToVisit - totalClientsNoVisit).ToString() + "*Clientes&nbspsin&nbspvisitar:&nbsp" + totalClientsNoVisit.ToString();
                columnInfoTotal.LineBottom = "<strong>Totales&nbspde&nbspla&nbspruta:</strong>*";

                if (int.Parse(row["TotalHours"].ToString()) > 0)
                {
                    timeVisit = row["TotalHours"].ToString() + "&nbsph&nbsp";
                }

                timeVisit += row["TotalMinutes"].ToString() + "&nbspmin";

                columnInfoTotal.LineBottom += "Estadía:&nbsp" + timeVisit + "*";

                if (int.Parse(row["TotalHoursTravel"].ToString()) > 0)
                {
                    timeTravel = row["TotalHoursTravel"].ToString() + "&nbsph&nbsp";
                }

                timeTravel += row["TotalMinutesTravel"].ToString() + "&nbspmin";

                columnInfoTotal.LineBottom += "Tiempo&nbspRuta:&nbsp" + timeTravel + "*";

                columnInfoTotal.LineBottom += "Kilometros&nbspRecorridos:&nbsp" + row["TotalDistanceKmTravel"].ToString() + "&nbspKm*";

                if (int.Parse(row["TotalGlobalHours"].ToString()) > 0)
                {
                    timeGlobal = row["TotalGlobalHours"].ToString() + "&nbsph&nbsp";
                }

                timeGlobal += row["TotalGlobalMinutes"].ToString() + "&nbspmin";

                columnInfoTotal.LineBottom += "<strong>Tiempo&nbspTotal:&nbsp" + timeGlobal + "</strong>";
                columnInfoTotal.ColorSeparate = System.Drawing.Color.Red;
            }

            if (isEstimatedGrid)
            {
                lblTitleTable1.Text = "Óptimo";
                BuildTable(Table1, listColumnInfo, columnInfoTotal);
            }
            else
            {
                lblTitleTable2.Text = "Último Realizado";
                BuildTable(Table2, listColumnInfo, columnInfoTotal);
            }
        }

        public void getStaticsTables() {
            
            List<ColumnInfo> listColumnInfo = new List<ColumnInfo>();

            ColumnInfo info = new ColumnInfo();
            info.ClientName = "Compañia";
            info.HomeImage = HomeType.Red;
            info.LineColor = System.Drawing.Color.Red;
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.LineColor = System.Drawing.Color.Red;
            info.HomeImage = HomeType.None;
            info.TimeText = "Tiempo ruta*1:06 Horas*8.9 Km";
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.ClientName = "Rest. Mei Tou";
            info.HomeImage = HomeType.Green;
            info.LineColor = System.Drawing.Color.Red;
            info.TimeText = "Estadia*30 Min";
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.HomeImage = HomeType.None;
            info.LineColor = System.Drawing.Color.Red;
            info.TimeText = "Tiempo ruta*15 Minutos*1.1 Km";
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.ClientName = "Bar Zuñiga";
            info.HomeImage = HomeType.Lile;
            info.LineColor = System.Drawing.Color.Red;
            info.TimeText = "Estadia*30 Min";
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.HomeImage = HomeType.None;
            info.LineColor = System.Drawing.Color.Red;
            info.TimeText = "Tiempo ruta*6 Minutos*1.9 Km";
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.ClientName = "Rest. Las Cavitas";
            info.HomeImage = HomeType.Lile;
            info.LineColor = System.Drawing.Color.Red;
            info.TimeText = "Estadia*30 Min";
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.HomeImage = HomeType.None;
            info.LineColor = System.Drawing.Color.Red;
            info.TimeText = "Tiempo ruta*8 Minutos*0.4 Km";
            listColumnInfo.Add(info);

            info = new ColumnInfo();
            info.ClientName = "Bar La Admistad";
            info.HomeImage = HomeType.Fail;
            info.LineColor = System.Drawing.Color.Red;
            info.TimeText = "Estadia*30 Min";
            listColumnInfo.Add(info);


            //Total Section
            ColumnInfoTotal columnInfoTotal = new ColumnInfoTotal();
            columnInfoTotal.LineTop = "<strong>Costos Adicionales:</strong>*Kilometros Extras: 4 Km*Porcentaje Clientes Visitados: 71%*Porcentaje Clientes sin visitar: 21%*Ventas Prom. no se realizaron ______";
            columnInfoTotal.LineBottom = "<strong>Totales de la ruta:</strong>*Estadia: 2:08 Horas*Tiempo ruta: 3:20 Horas*Kilometros recorridos: 24.6 Km*<strong>Tiempo total: 5:28 Horas</strong>";
            columnInfoTotal.ColorSeparate = System.Drawing.Color.Red;

            lblTitleTable1.Text = "Optimo";
            BuildTable(Table1, listColumnInfo, columnInfoTotal);





            lblTitleTable2.Text = "Ultimo Realizado";
            BuildTable(Table2, listColumnInfo, columnInfoTotal);

            //lblTitleTable3.Text = "Promedio";
            //BuildTable(Table3, listColumnInfo, columnInfoTotal);

        }

        public void BuildTable(System.Web.UI.HtmlControls.HtmlTable table, List<ColumnInfo> listInfo, ColumnInfoTotal infoTotal)
        {
            
            foreach (ColumnInfo info in listInfo)
            {
                System.Web.UI.HtmlControls.HtmlTableCell clientNameCell = new System.Web.UI.HtmlControls.HtmlTableCell();
                clientNameCell.InnerText = info.ClientName;
                clientNameCell.Align = HorizontalAlign.Center.ToString();

                System.Web.UI.HtmlControls.HtmlTableCell homeImageCell = new System.Web.UI.HtmlControls.HtmlTableCell();
                if (info.HomeImage != HomeType.None)
                {
                    System.Web.UI.HtmlControls.HtmlImage htmlImage = new System.Web.UI.HtmlControls.HtmlImage();
                    htmlImage.Src = "../../Template/Icons/32px/" + EnumString.GetStringValue(info.HomeImage);
                    homeImageCell.Controls.Add(htmlImage);
                    homeImageCell.Align = HorizontalAlign.Center.ToString();
                }

                System.Web.UI.HtmlControls.HtmlTableCell lineColorCell = new System.Web.UI.HtmlControls.HtmlTableCell();
                lineColorCell.BgColor = info.LineColor.ToKnownColor().ToString();

                System.Web.UI.HtmlControls.HtmlTableCell textInfoCell = new System.Web.UI.HtmlControls.HtmlTableCell();
                if (!string.IsNullOrEmpty(info.TimeText ))
                {
                    textInfoCell.InnerHtml = info.TimeText.Replace("*", "<br />");
                    textInfoCell.Align = HorizontalAlign.Center.ToString();                  
                }

                table.Rows[0].Cells.Add(clientNameCell);
                table.Rows[1].Cells.Add(homeImageCell);
                table.Rows[2].Cells.Add(lineColorCell);
                table.Rows[3].Cells.Add(textInfoCell);
            }

            //Total section
            for (int i = 0; i < 4; i++)
            {
                System.Web.UI.HtmlControls.HtmlTableCell colorSeparate = new System.Web.UI.HtmlControls.HtmlTableCell();
                colorSeparate.BgColor = infoTotal.ColorSeparate.ToKnownColor().ToString();
                table.Rows[i].Cells.Add(colorSeparate);
            }



            System.Web.UI.HtmlControls.HtmlTableCell lineTopCell = new System.Web.UI.HtmlControls.HtmlTableCell();
            lineTopCell.InnerHtml = infoTotal.LineTop.Replace("*", "<br />");
            lineTopCell.RowSpan = 2;
            table.Rows[0].Cells.Add(lineTopCell);

            System.Web.UI.HtmlControls.HtmlTableCell lineBottomCell = new System.Web.UI.HtmlControls.HtmlTableCell();
            lineBottomCell.InnerHtml = infoTotal.LineBottom.Replace("*", "<br />");
            lineBottomCell.RowSpan = 2;
            table.Rows[2].Cells.Add(lineBottomCell);

        }


    }
}